/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package programaobf;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
/**
 *
 * @author MSK
 */
public class PDFwritera{
    public String pdffistr;
    public String pdffistr1;    
    public static String nwl = System.getProperty("line.separator");
    FileInputStream fis = null;
    BufferedInputStream bis = null;
    DataInputStream dis = null;
    FileOutputStream fos = null;
    BufferedOutputStream bos = null;
    DataOutputStream dos = null;
    PDFwritera(File coloap, File pdfrep1) throws FileNotFoundException, IOException{
        pdffistr="%PDF-1.4"+nwl
        +"1 0 obj <</Type/Catalog/Pages 2 0 R/Lang(bg-BG) >>"+nwl
        +"endobj"+nwl
        +"2 0 obj <</Type /Pages /Kids [3 0 R] /Count 1>>"+nwl
        +"endobj"+nwl
        +"3 0 obj<</Type /Page /Parent 2 0 R /Resources 4 0 R /MediaBox [0 0 595.2756 841.8898] /Contents 6 0 R>>"+nwl
        +"endobj"+nwl
        +"4 0 obj<</Font <</F1 5 0 R>>>>"+nwl
        +"endobj "+nwl
        +"5 0 obj <</Type/Font/Arial>>"+nwl
        +"endobj"+nwl
        +"6 0 obj"+nwl
        +"<</Length 440>>"+nwl
        +"stream"+nwl
        +"BT /F1 24 Tf 200 800 Td (Nai-atraktivni promocii)Tj ET"+nwl
        +"BT /F1 15 Tf 50 770 Td (Broj poseshtenia)Tj ET"+nwl
        +"BT /F1 15 Tf 175 770 Td (Promocia)Tj ET"+nwl
        +"BT /F1 15 Tf 325 770 Td (Vunshni stranici)Tj ET"+nwl;
        //+strem+nwl
        pdffistr1="endstream"+nwl
        +"endobj"+nwl
        +"xref"+nwl
        +"0 7"+nwl
        +"0000000000 65535 f"+nwl
        +"0000000009 00000 n"+nwl
        +"0000000056 00000 n"+nwl
        +"0000000111 00000 n"+nwl
        +"0000000212 00000 n"+nwl
        +"0000000250 00000 n"+nwl
        +"0000000317 00000 n"+nwl
        +"trailer <</Size 7/Root 1 0 R>>"+nwl
        +"startxref"+nwl
        +"406"+nwl
        +"%%EOF";
        int coun;
        if(coloap.exists()){
          fis = new FileInputStream(coloap);
          bis = new BufferedInputStream(fis);
          dis = new DataInputStream(bis);
          fos = new FileOutputStream(pdfrep1);
          bos = new BufferedOutputStream(fos);
          dos = new DataOutputStream(bos);
          dos.writeBytes(pdffistr);
          coun=750;
          while (dis.available() != 0 ){
              String barev =  dis.readLine();
              String[] rebac = barev.split(" ");
              dos.writeBytes(pdfstrut(coun, rebac[0], rebac[1], rebac[2]) + nwl);
              coun=coun-15;
          }
          dos.writeBytes(pdffistr1);
          fos.flush();
          dos.flush();
          fos.close();
          bis.close();
          dos.close();
          fis.close();
          bis.close();
          dis.close();
          System.out.println("The file has been written "+pdfrep1);
          }
          else{
            System.out.println("This file is not exist");}
          }
    String pdfstrut(int srm,String pro1,String pro2,String pro3)
    {
        String strem;
        strem = "BT /F1 12 Tf 50 "+srm+" Td ("+pro1+")Tj ET"+nwl+"BT /F1 12 Tf 175 "+srm+" Td ("+pro2+")Tj ET"+nwl+"BT /F1 12 Tf 325 "+srm+" Td ("+pro3+")Tj ET";
        return strem;
    }

}
